// pages/orderlist/orderlist.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    stare: '',
    stares: '',
    order: [],
    type: '',
    page: 2,
    tab:[]
  },
  refund(e){
    let oid=e.currentTarget.id
    wx.request({
      url: 'http://fbj.wdmnm.vip/api/refundPrice',
      data: {
        uid:wx.getStorageSync('uid'),
        token: wx.getStorageSync('token'),
        oid:oid
      },
      success: function (res) {
        if (res.data.code==200) {
    
        }
      }
    })
  },
  //订单详情页
  orderxiang(e) {
    // console.log(e.currentTarget.id);
    var id = e.currentTarget.id
    wx.navigateTo({
      url: '/pages/orderxiang/orderxiang?id=' + id,
    })
  },
  //导航页获取数据
  changeTabs(e) {
    let tab_id = e.detail.activeKey
    let that = this
    wx.request({
      url: 'http://fbj.wdmnm.vip/api/orderList',
      data: {
        status: tab_id,
        uid:wx.getStorageSync('uid'),
        token: wx.getStorageSync('token'),
      },
      dataType: 'json',
      success: function (res) {
        if (res.data.code==200) {
          that.setData({
            order: res.data.data,
            page: 2,
            stares: ''
          })
        }
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    wx.request({
      url: 'http://fbj.wdmnm.vip/api/orderList',
      data: {
        token: wx.getStorageSync('token'),
        uid:wx.getStorageSync('uid')
      },
      dataType: 'json',
      success: function (res) {
        if (res.data.code == 200) {
          that.setData({
            order: res.data.data
          })
        } else {
          that.setData({
            stare: true,
            good: res.data.good.data
          })
        }
        if (res.data.code == 501) {
          wx.showToast({
            title: res.data.msg,
            icon: 'error',
            duration: 2000,
            success: function () {
              setTimeout(function () {
                //要延时执行的代码
                wx.navigateTo({
                  url: '/pages/index/index'
                })
              }, 2000) //延迟时间
            }
          })
        }
      }
    })
    wx.request({
      url: 'http://fbj.wdmnm.vip/api/tabList',
      success:function(res){
        if(res.data.code==200){
          that.setData({
            tab:res.data.data
          })
        }
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this
    wx.request({
      url: 'http://fbj.wdmnm.vip/api/orderList',
      data: {
        page: that.data.page,
        type: that.data.type,
        token: wx.getStorageSync('token')
      },
      dataType: 'json',
      success: function (res) {
        if (res.data.code== 0) {
          var lists = that.data.list
          that.setData({
            list: lists.concat(res.data.data.data),
            page: that.data.page + 1
          })
        } else {
          wx.showToast({
            title: '没有更多数据',
            icon: 'error',
            duration: 2000
          })
        }
      }
    })
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return {
      title: "分享擦二十"
    }
  }
})